<template>
  <div class='container'>
    <el-dialog title="审核" :visible="checkVisible" @close="handleClose" width="400px">
        <el-form :model="formData" ref="form" :rules="rules" >
          <el-form-item  prop="chkState">
            <el-radio-group v-model="formData.chkState" >
              <el-radio :label="1">同意</el-radio>
              <el-radio :label="2">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item prop="chkRemarks">
            <el-input type="textarea" placeholder="请输入审核意见" v-model="formData.chkRemarks"></el-input>
          </el-form-item>
           <el-form-item style="text-align:end">
            <el-button type="info" @click="handleClose">取消</el-button>
            <el-button type="primary" @click="handleSubmit">确定</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'QuestionsCheck',
  data () {
    return {
      // 审核对话框数据
      formData: {
        chkState: 1,
        chkRemarks: ''
      },
      // 校验规则
      rules: {
        chkRemarks: [
          { required: true, trigger: ['blur', 'change'], message: '意见不能为空' }
        ]
      }
    }
  },
  props: {
    checkVisible: {
      type: Boolean,
      default: false
    },
    checkId: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 审核意见提交
    handleSubmit () {
      this.$refs.form.validate(async (val) => {
        console.log(val)
        if (val) {
          console.log(111)
          await choiceCheck({
            id: this.checkId,
            ...this.formData
          })
          this.$message.success('审核成功')
          this.handleClose()
          this.$emit('reload')
        } else {
          this.$message.warning('请填入审核意见')
        }
      })
    },
    // 关闭对话框
    handleClose () {
      this.$emit('update:checkVisible', false)
      this.formData = {
        chkState: 1,
        chkRemarks: ''
      }
    }

  }
}
</script>

<style scoped lang='less'></style>
